package com.d6game.purchase;

import com.d6game.purchase.util.SysApplication;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class HomeActivity extends Activity implements OnClickListener{
	TextView goods,shop,color,export,search,about;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		SysApplication.getInstance().addActivity(this);
		setContentView(R.layout.activity_home);
		goods = (TextView) findViewById(R.id.tv_goods);
		goods.setOnClickListener(this);
		shop = (TextView) findViewById(R.id.tv_shop);
		shop.setOnClickListener(this);
		color = (TextView) findViewById(R.id.tv_color);
		color.setOnClickListener(this);
		export = (TextView) findViewById(R.id.tv_export);
		export.setOnClickListener(this);
		search = (TextView) findViewById(R.id.tv_search);
		search.setOnClickListener(this);
		about = (TextView) findViewById(R.id.tv_about);
		about.setOnClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		//getMenuInflater().inflate(R.menu.home, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		if (v == goods) {
			Intent intent = new Intent(this,GoodsListActivity.class);
			startActivity(intent);
		}else if (v == shop) {
			Intent intent = new Intent(this,ShopListActivity.class);
			startActivity(intent);
		}else if (v == color) {
			Intent intent = new Intent(this,ColorListActivity.class);
			startActivity(intent);
		}else if (v == export) {
			Intent intent = new Intent(this,ExportActivity.class);
			startActivity(intent);
		}else if (v == search) {
			Intent intent = new Intent(this,SearchActivity.class);
			startActivity(intent);
		}
		else if (v == about) {
			Intent intent = new Intent(this,AboutActivity.class);
			startActivity(intent);
		}
	}
	@Override
	public void onBackPressed() {

		new AlertDialog.Builder(this) 
	 	.setTitle(this.getResources().getText(R.string.confirm).toString())
	 	.setMessage(this.getResources().getText(R.string.confirm_exit).toString())
	 	.setPositiveButton(this.getResources().getText(R.string.ok).toString(), new DialogInterface.OnClickListener(){

			@Override
			public void onClick(DialogInterface dialog, int which) {
				SysApplication.getInstance().exit();
			}
	 	})
	 	.setNegativeButton(this.getResources().getText(R.string.cancel).toString(), null)
	 	.show();
	
	}
}
